<?php
declare(strict_types=1);


namespace App\Mall\Mapper;

use App\Mall\Model\MallOrder;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 订单Mapper类
 */
class MallOrderMapper extends AbstractMapper
{
    /**
     * @var MallOrder
     */
    public $model;

    public function assignModel()
    {
        $this->model = MallOrder::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        // 用户id
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 订单编号
        if (isset($params['no']) && filled($params['no'])) {
            $query->where('no', '=', $params['no']);
        }

        // 支付0否1是
        if (isset($params['is_pay']) && filled($params['is_pay'])) {
            $query->where('is_pay', '=', $params['is_pay']);
        }

        // 1正常2取消3超时
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        return $query->with(['item']);
    }
}